/*-----------------------------------------------------------------------------
*
*	Copyright (C) 2011 ALI Corp. All rights reserved.
*
*	File: osd_common_draw.c
*
*	Content: 
*		control GE draw
*	History: 
*		
*		Created this file. osd lib draw use ge draw
*-----------------------------------------------------------------------------*/

#include <sys_config.h>
#include <api/libosd/osd_lib.h>
#include <api/libosd/osd_common_draw.h>
#include <api/libc/string.h>
#include <api/libchar/lib_char.h>

#define  OSD_DRAW_TASK  36
static INT32    record[OSD_DRAW_TASK] = {0};
static volatile BOOL b_start_ge_draw = FALSE;
static BOOL     b_g_is_vscr = TRUE;

void OSD_GeDraw_Init(UINT32 handle,BOOL b_vscr,INT32  pixel_patch)
{
    UINT32 task_id;
    UINT8 *reg_buf = NULL; 
    task_id = osal_task_get_current_id();

    osal_task_dispatch_off();
    b_g_is_vscr = b_vscr;
    osal_task_dispatch_on();
    
    if(!b_vscr)
    {
        if(OSD_GetTaskVscrBuffer(task_id) != NULL)
        {
            OSD_TaskBuffer_Free(task_id,OSD_GetTaskVscrBuffer(task_id));
        }
        OSDDrv_GetRegionAddr(handle,0,0,&reg_buf);
        OSD_TaskBuffer_Init(task_id,reg_buf);        
    }    
}

BOOL OSD_Get_Vscr_State(void)
{
    return b_g_is_vscr;
}



void OSD_Draw_Recode_Ge_Cmd_Start(void)
{
    INT32 id = osal_task_get_current_id();
    
    if(record[id] == 0)
    {   
        if(!OSD_Get_Vscr_State())
        {
#ifdef GE_DRAW_OSD_LIB
            lib_ge_draw_start();
#endif
        }
    }
    
    osal_task_dispatch_off();
    record[id]++;
    osal_task_dispatch_on();
   
}

void OSD_Draw_Recode_Ge_Cmd_Stop(void)
{
    INT32 id = osal_task_get_current_id();
  
    osal_task_dispatch_off();
    record[id]--;
    osal_task_dispatch_on();
    
    if(record[id] <= 0)
    {
        if(!OSD_Get_Vscr_State())
        {
#ifdef GE_DRAW_OSD_LIB            
            lib_ge_draw_end();
#endif
        }
        record[id] = 0;
    }
   
}


